package org.noka.star;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;

import org.nokatag.system.BugInfoWrint;
import org.nokatag.tagjava.Inputsuper;
/**
 * *******************************************************
 * <p>@Description 星级评分插件</p>
 * <p>@Version 1.0.0</p>
 * <p>@author rebin</p>
 * <p>@time 2017年4月20日 上午9:11:22</p>
 * <p>xiefangjian@163.com</p>
 * <p>Copyright © Noka Laboratory.All Rights Reserved.</p>
 * *****************************************************
 */
public class NStarTag extends Inputsuper{
	private static final long serialVersionUID = -524771441810342629L;
	private String maxvalue = "5";//最大值,最小值为1,1-5
	public int doStartTag()throws JspException{
		Integer val =Integer.parseInt(null==getValue()?"0":getValue());//值
		Integer maxval = Integer.parseInt(getMaxvalue());//最大值
		maxval = (maxval<val?val:maxval);
		JspWriter jspOut = pageContext.getOut();
		NOOUT.put("classstyle", true);
		NOOUT.put("style", true);
		NOOUT.put("onclick", true);
		NOOUT.put("readonly", true);
		NOOUT.put("disabled", true);
		NOOUT.put("onchange", true);
		FormHtmlInsertid(getId(),getName(),getValue());//给动态表单使用
		String pwidth = getWidth();
		pwidth =LenFormat((pwidth==null)?"120":pwidth);
		HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
		StringBuilder body = new StringBuilder();
		body.append(potjs(request));
		body.append(nstar(request));
		String basePath = basepath(request);
		body.append("<div id=\""+getId()+"_div\" "+(null==getStyle()?"":"style=\""+getStyle()+"\"")+" "+(null==getClassstyle()?"":"class=\""+getClassstyle()+"\"")+"></div>");
		body.append("<script type=\"text/javascript\">");
		body.append("Event.observe(document, 'dom:loaded', function() {");
		body.append("var nkstar"+getId()+" = {");
		body.append("id:'"+getId()+"',");//id
		body.append("rurl:'"+basePath+"',");//根url
		if(null!=getValue()){
			body.append("value:"+val+",");
		}
		if(null!=getName()){
			body.append("name:'"+getName()+"',");
		}
		if(null!=getReadonly()){
			body.append("readonly:'"+getReadonly()+"',");
		}
		if(null!=getDisabled()){
			body.append("disabled:'"+getDisabled()+"',");
		}
		if(null!=getOnclick()){
			body.append("onclick:function(a){"+getOnclick()+"(a);},");
		}
		if(null!=getOnchange()){
			body.append("onchange:function(a){"+getOnchange()+"(a);},");
		}
		body.append("maxvalue:"+maxval+"");
		body.append("};");
		body.append("var nks"+getId()+" = new nstar(nkstar"+getId()+");");
		body.append("nks"+getId()+".show();");
		body.append("});");
		body.append("</script>");
		try {
			jspOut.write(body.toString());
		} catch (IOException e) {
			BugInfoWrint.Print(e);
		}
		return EVAL_BODY_INCLUDE;
	}
	public String getMaxvalue() {
		return maxvalue;
	}
	public void setMaxvalue(String maxvalue) {
		this.maxvalue = maxvalue;
	}
}
